<template>
	<view class="content">
		<view class="header">
			<view class="tap">
				<view class="tap-item" :class="tap == 0 ? 'active':''" data-index="0" @click="changeTap">
					我要鉴宝
				</view>
				<view class="tap-item" :class="tap == 1 ? 'active':''" data-index="1" @click="changeTap">
					预约过户
				</view>
			</view>
		</view>
		<view class="list" v-if="datasource.length>0">
			<appoinmentItem v-for="(item,index) in datasource" :key="index" :datasource="item" :isTreasure="tap==0" @cancelAppointment='cancelAppointment'>
			</appoinmentItem>
		</view>
		<view class="list" v-else>
			<noData></noData>
		</view>
		<noMoreData v-if="isBottom && datasource.length>0"></noMoreData>
	</view>
</template>

<script>
	import appoinmentItem from '@/components/appointment-item/index.vue'
	import noMoreData from '@/components/noMoreData/index.vue'
	import noData from '@/components/noData/index.vue'
	import {
		judgeList,
		transList
	} from '@/api/peopleHide.js'
	import {
		getUserInfo
	} from '@/api/user.js';
	export default {
		components: {
			appoinmentItem,
			noData,
			noMoreData
		},
		data() {
			return {
				tap: 0,
				noData: true,
				page: 1,
				limit: 15,
				datasource: [],
				isBottom: false
			}
		},
		onLoad(options) {
			 
			if (options.tap) {
				this.tap = options.tap
			}
			this.getDatasource()
			
		},
		onReachBottom() {
			this.page++
			this.getDatasource()
		},
		methods: {
			
			changeTap(e) {
				let index = e.currentTarget.dataset.index
				if (this.tap != index) {
					this.tap = index
					this.page = 1
					this.getDatasource()
				}
				
			},
			cancelAppointment(){
			  this.page = 1	
			  this.getDatasource()
			},
			getDatasource() {
				if (this.tap == 0) {
					this.judgeList()
				} else {
					this.transList()
				}
			},
			judgeList() { //我的鉴宝预约列表
				judgeList({
					page: this.page,
					limit: this.limit
				}).then(res => {
					let data = []
					if (this.page == 1) {
						data = res.data
					} else {
						data = this.datasource.concat(res.data)
					}
					this.datasource = data
					this.isBottom = res.data.length < this.limit ? true : false
				})
			},
			transList() { //预约过户列表
				transList({
					page: this.page,
					limit: this.limit
				}).then(res => {
					let data = []
					if (this.page == 1) {
						data = res.data
					} else {
						data = this.datasource.concat(res.data)
					}
					this.datasource = data
					this.isBottom = res.data.length < this.limit ? true : false
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f4f5f6;
	}

	.header {
		display: flex;
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		flex-direction: column;
		align-items: center;
		z-index: 99;
		background-color: #fff;
		box-shadow: 0px 4rpx 8rpx 0px rgba(236, 236, 236, 0.50);
		box-sizing: border-box;

		.tap {
			width: 100%;
			height: 94upx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.tap-item {
				display: flex;
				align-items: center;
				justify-content: center;
				height: 100%;
				flex: 1;
				position: relative;
				font-size: 32upx;
				font-weight: 400;
			}

			.active {
				color: #0A77DE;
				font-weight: 500;
			}

			.active:after {
				position: absolute;
				content: '';
				bottom: 0;
				width: 50upx;
				background-color: #0A77DE;
				height: 2upx;
			}
		}
	}

	.list {
		margin-top: 114upx;
	}
</style>
